<?php
/**
 * Nad�b (Mak�-Nad�b)
 *
 * @filesource 
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    Freeware
 * @package    Nadeb_File_UploadFiles
 * @subpackage Nadeb.Grid.Sql
 * @version    1.0
 */

class Nadeb_File_UploadFiles
{
	private $file_name;
	
	public function save_file($_file,$_path)
	{
		$target_path = $_SERVER['DOCUMENT_ROOT'] . ROOT . $_path;
		$file        = $_file;
		
		@mkdir($target_path, 0777,true);
		@chmod($target_path, 0777,true);
		
		$this->file_name = $this->numeric_name($file['name']);
		if(move_uploaded_file($file['tmp_name'], $target_path.$this->file_name ))
			return $this->file_name;
		else
			return false;
	}
	
	public function get_file_name()
	{
		return $this->file_name;
	}
	
	private function numeric_name($name)
	{
		$ar_name = explode(".",$name);
		$ext = strtolower(".".$ar_name[count($ar_name)-1]);
			
		$rnd_name = md5( date("YmdHis") . rand(1000000000001, 9999999999999) );
	    $new_name = $rnd_name.$ext;
	
	    return $new_name;
	}
}